package br.ufrn.imd.classificados.adapter;

import java.util.ArrayList;

import br.ufrn.imd.classificados.dominio.Item;
import br.ufrn.imd.imd0023_classificados.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Arranjamento dos itens.
 * @author Pablo
 *
 */
public class ItemAdapter extends BaseAdapter {
	
	private LayoutInflater mInflater;
	private ArrayList<Item> itens;
	
	public ItemAdapter(Context context, ArrayList<Item> itens) {
		this.itens = itens;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return itens.size();
	}

	@Override
	public Object getItem(int position) {
		return itens.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Item item = itens.get(position);
		
		view = mInflater.inflate(R.layout.item, null);
		ImageView imagemItem = (ImageView) view.findViewById(R.id.imagemItem);
		TextView nomeItem = (TextView) view.findViewById(R.id.nomeItem);
		
		imagemItem.setImageResource(R.drawable.product_icon);
		nomeItem.setText(item.getNome());
		
		return view;
	}

}
